////<!--违规流水-->
import api from '../../../fetch/api'

export default {
    data() {
        return {
            bigImgPath: '',
            violateTypeList: [],
            newViolateTypeList: {
                list: []
            },
            picPath:[],
            delNo: '',
            delId: '',
        }
    },
    created() {
        this.getEventTypeSimpleList();
    },
    methods: {
        getList() {
            let params = $.extend({}, this.searchParams, this.otherParams);
            //console.log(this.otherParams)
            this.getItemList(params);
        },
        showBigImgModal(name, path) {
            this.bigImgPath = path;
            this.toOpenImgModal(name, path);
        },
        showPicModal(name, path) {
            this.picPath = path;
            this.toOpenImgModal(name, path);
        },
        //获取列表
        getItemList(aparams) {
            let self = this,
                params = {
                    page: self.pageNumber,
                    pageSize: self.pageSize
                };
            params = $.extend(params, aparams);

            api.fetchGet('mobile/parkingViolate/list.do', params)
                .then(res => {
                    // console.log('getListResult', res)
                    let data = res.data;
                    self.tbodysInfo = data.rows;
                    self.total = data.total;
                }, err => { })
        },
        exportData() {
            let self = this;
            let theadsArr = []
            for(let i = 0; i<self.theadsInfo.length; i++){
            if(self.theadsInfo[i].checked){
                theadsArr.push(self.theadsInfo[i].prop)
            }
            }
            let params = {
                meterList: theadsArr.join(',')
            };
            params = $.extend({}, params, this.searchParams, this.otherParams);
            self.showDialog("确认导出该报表?", '', function () {
                self.toExportAsync('mobile/parkingViolate/export.do', params);
            });
        },
        getEventTypeSimpleList() {
            let self = this;
            api.fetchGet('mobile/parkingViolate/violateType/listSimple.do', null)
                .then(res => {
                    var dataList = res.data;
                    dataList.unshift({ name: '全部', value: '' });
                    self.searchList[4].options = dataList;
                }, err => { })
        },
        getEventTypeList() {
            let self = this;
            api.fetchGet('mobile/parkingViolate/violateType/list.do', null)
                .then(res => {
                    self.violateTypeList = res.data;
                }, err => { });
        },
        showViolateTypeModal(modalName) {
            this.newViolateTypeList.list = [];
            this.getEventTypeList();
            this.toOpenModal(modalName);
        },
        delConfirmTipModal_del_open(index,id) {
            this.delNo=index;
            this.id=id;
            this.toOpenModal('delConfirmTipModal');
        },
        delViolateType(index, id) {
            if (id) {
                let self = this;
                api.fetchGet('mobile/parkingViolate/violateType/delete.do', { 'id': id })
                    .then(res => {
                        if (res.status == 1) {
                            self.getEventTypeList();
                            self.getEventTypeSimpleList();
                        }
                    }, err => { });
            } else {
                this.newViolateTypeList.list.splice(index, 1);
            }
            this.closed('delConfirmTipModal', 1);
        },
        addViolateType() {
            this.newViolateTypeList.list.push({
                id: 0,
                eventType: '',
                channelEventCode: ''
            });
        },
        submitViolateTypeForm() {
            let self = this;
            if (self.newViolateTypeList.list.length > 0) {
                this.$refs['violateTypeForm'].validate((valid) => {
                    if (valid) {
                        api.fetchPost('mobile/parkingViolate/violateType/batchSave.do', self.newViolateTypeList.list)
                            .then(res => {
                                if (res.status == 1) {
                                    self.showToast('保存成功', 1);
                                    self.closed('violateTypeModal');
                                    self.getEventTypeSimpleList();
                                }
                            }, err => { });
                    } else {
                        return false;
                    }
                });
            } else {
                self.closed('violateTypeModal');
            }
        }
    }
}